package com.yunqiao.admin.modules.api.controller;

import java.util.Arrays;
import java.util.Map;

import com.yunqiao.common.validator.Assert;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.yunqiao.service.api.entity.ApplyDriverEntity;
import com.yunqiao.service.api.ApplyDriverService;
import com.yunqiao.common.utils.PageUtils;
import com.yunqiao.common.utils.R;


/**
 * 用户申请为司机
 *
 * @author Crocutax
 * @email wangxw725@163.com
 * @date 2019-03-16 15:25:51
 */
@RestController
@RequestMapping("api/applydriver")
//@Api(tags = "ApplyDriverController" ,description = "用户申请成为司机管理")
public class ApplyDriverController {

    @Autowired
    private ApplyDriverService applyDriverService;

    /**
     * 列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "status", value = "1:申请中,2:已同意,3:已拒绝",allowableValues = "1,2,3",required = false ,defaultValue = "1",paramType = "query" , dataType = "int"),
            @ApiImplicitParam(name = "page", value = "页码", required = false ,defaultValue = "1",paramType = "query" , dataType = "int"),
            @ApiImplicitParam(name = "limit", value = "数量", required = false,defaultValue = "10",paramType = "query" , dataType = "int")
    })
    @GetMapping("/list")
    //@ApiOperation("查询列表")
//    @RequiresPermissions("api:applydriver:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = applyDriverService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@ApiOperation("查询单个用户申请")
//    @RequiresPermissions("api:applydriver:info")
    public R info(@PathVariable("id") Long id){
        ApplyDriverEntity applyDriver = applyDriverService.getById(id);
        return R.ok().put("applyDriver", applyDriver);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//    @ApiOperation("保存申请")
//    @RequiresPermissions("api:applydriver:save")
    public R save(@RequestBody ApplyDriverEntity applyDriver){
        applyDriverService.save(applyDriver);
        return R.ok();
    }


    /**
     * 审核
     * @param applyDriver
     * @return
     */
    @PostMapping("/auditApply")
    public R auditApply(@RequestBody ApplyDriverEntity applyDriver){
        Assert.isNull(applyDriver.getId(),"ID不能为空");
        Assert.isNull(applyDriver.getStatus(),"审核结果不能为空");
        applyDriverService.auditApply(applyDriver);
        return R.ok();
    }



    /**
     * 修改
     */
    @RequestMapping("/update")
//    @ApiOperation("修改申请")
//    @RequiresPermissions("api:applydriver:update")
    public R update(@RequestBody ApplyDriverEntity applyDriver){
        applyDriverService.updateById(applyDriver);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
//    @ApiOperation("删除申请")
//    @RequiresPermissions("api:applydriver:delete")
    public R delete(@RequestBody Long[] ids){
        applyDriverService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
